package com.spider.admin.service.accountPerm;


import com.spider.admin.exception.SpiderException;
import com.spider.admin.service.async.AsyncService;
import com.spider.admin.store.primary.mapper.AccountServicePermMapper;
import com.spider.admin.store.primary.model.AccountServicePerm;
import com.spider.admin.utils.CommonUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AccountServicePermServiceImpl implements AccountServicePermService {

    @Autowired
    AccountServicePermMapper accountServicePermMapper;

    @Resource
    private AsyncService asyncService;


    @Override
    public int saveAccountServicePerm(AccountServicePerm accountServicePerm) throws SpiderException {
        accountServicePerm.setPid(CommonUtil.getUniqueKey()).setVPid(CommonUtil.md5(accountServicePerm.getAccount() + accountServicePerm.getServiceId()));
        int i = accountServicePermMapper.saveAccountPerm(accountServicePerm);
        asyncService.asyncRefashPermsCache();
        return i;
    }

    @Override
    public int deleteAccountServicePerm(String account, String serviceId) throws SpiderException {
        int i = accountServicePermMapper.delAccountPermByAccountAndServiceId(account, serviceId);
        asyncService.asyncRefashPermsCache();
        return i;
    }
}
